﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>加载图层控件（自定义）</title>
    <link href="js/v5.1.3-dist/ol.css" rel="stylesheet" type="text/css" />
    <script src="js/v5.1.3-dist/ol.js" type="text/javascript"></script>
    <link href="css/example.css" rel="stylesheet" />
    <script src="js/InitMap.js"></script>
</head>
<body>
    <div id="map"> 
    </div>
    <script type="text/javascript">
       

        //实例化Map对象加载地图
        var map = new ol.Map({
            target: 'map', //地图容器div的ID
            //地图容器中加载的图层
            layers: [
                //中国影像
                new ol.layer.Tile({
                    source: new ol.source.XYZ({
                        wrapX: false,
                        tileUrlFunction: tileUrlFunction1
                    }),
                    name: "必应地图"

                })

            ],
            //地图视图设置
            view: new ol.View({
                center: [120, 28],
                projection: ol.proj.get("EPSG:4326"),
                zoom: 2 //地图初始显示级别
            })
        });
        //加载图层列表数据
        loadLayersControl(map, "layerTree");




        // Bing地图
        function tileUrlFunction1(coord, params1, params2) {
            return getVETileUrl("http://dynamic.t0.tiles.ditu.live.com/comp/ch/", coord[0], coord[1], -coord[2] - 1);
        }

        // Bing影像
        function tileUrlFunction1(coord, params1, params2) {
            return getVETileUrl("http://dynamic.t0.tiles.ditu.live.com/comp/ch/", coord[0], coord[1], -coord[2] - 1);
        }

        // Bing影像标注
        function tileUrlFunction1(coord, params1, params2) {
            return getVETileUrl("http://dynamic.t0.tiles.ditu.live.com/comp/ch/", coord[0], coord[1], -coord[2] - 1);
        }

        function getVETileUrl(url, z, x, y) {
            for (var a = "", c = x, d = y, e = 0; e < z; e++) {
                a = ((c & 1) + 2 * (d & 1)).toString() + a;
                c >>= 1;
                d >>= 1
            }
            return url + a + '?it=G,VE,BX,L,LA&mkt=zh-cn,syr&n=z&og=111&ur=CN'
        }


    </script>
</body>
</html>
